package com.baizhi.service.impl;

import com.baizhi.config.log.LogAnnotation;
import com.baizhi.entity.CmfzAlbum;
import com.baizhi.entity.R;
import com.baizhi.mapper.AlbumMapper;
import com.baizhi.service.AlbumService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class AlbumServiceImpl implements AlbumService {
    @Autowired
    private AlbumMapper albumMapper;
    @Transactional
    @LogAnnotation(content = "app查询专辑",type = "select")
    public R selectAlbum(Integer size) {
        log.debug(size+"");
        List<CmfzAlbum> records = null;
        try{
            Page page = new Page<CmfzAlbum>(1,size);
            QueryWrapper<CmfzAlbum> wrapper = new QueryWrapper<CmfzAlbum>().orderByDesc("album_date");
            Page<CmfzAlbum> page1 = albumMapper.selectPage(page, wrapper);
            records = page1.getRecords();
            return R.ok().put("data",records);
        }catch(Exception e){
            return R.error(1002,"专辑查询失败");
        }
    }

    @Transactional
    @LogAnnotation(content = "app查询专辑详情",type = "select")
    public R selectOneAlbum(Integer id) {
        try{
            CmfzAlbum cmfzAlbum = albumMapper.selectById(id);
            return R.ok().put("data",cmfzAlbum);
        }catch(Exception e){
            return R.error(1003,"专辑详情查询失败");
        }
    }

}
